﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using Supersense.db;

public partial class admin_product_doadd : System.Web.UI.Page
{
    public Database db = new Database();
    protected void Page_Load(object sender, EventArgs e)
    {
        string subject = Request.Form["subject"].Trim();
        string model = Request.Form["model"].Trim();
        string eventdate = Request.Form["eventdate"];
        int catid = Request.Form["catid"] == null ? 0 : Convert.ToInt32(Request.Form["catid"]);
        int type = Convert.ToInt32(Request.Form["type"].Trim());
        //string img = "/assets/images/product/" + model + ".jpg";
        string pathName = "";
        if (Request.Files != null)
        {
            string name = Request.Files["upload"].FileName;
            string extName = Path.GetExtension(Request.Files["upload"].FileName);
            string saveName = DateTime.Now.ToString("yyyyMMddHmmss") + extName;
            pathName = "/upload/" + saveName;
            Request.Files["upload"].SaveAs(Server.MapPath("~/")+"upload/"+saveName);
        }

        //if (file.HasFile)
        //{
        //    string img = DateTime.Now.ToString("yyyyMMddHHis") + file.FileName;
        //    file.PostedFile.SaveAs(Server.MapPath("~/uploads/") + img);
        //}
        string content = Request.Form["content"].Trim();

        //response.write(foreign_url == "");

        string settop = Request.Form["settop"].Trim();
        string sql = "INSERT INTO ss_product (name,model,eventdate,ss_product.type,ss_product.pdesc,istop,catid,img) values ";
        sql += "('" + subject + "','" + model + "','" + eventdate + "'," + type + ",'" + content + "','" + settop + "','" + catid + "','" + pathName + "')";
        if (this.db.executesql(sql))
        {
            Response.Write("<script type='text/javascript'>alert('您执行的操作成功了!')</script>");
            Response.Write("<meta http-equiv='refresh' content='0;url=add.aspx'/>");
        }
        else
        {
            Response.Write("<script type='text/javascript'>alert('您执行的操作失败了!');history.go(-1);</script>");
        }
    }

    
}